package cn.gson.fengboot.model.service;

import cn.gson.fengboot.model.dao.QproductDao;
import cn.gson.fengboot.model.dao.QpurDao;
import cn.gson.fengboot.model.dao.QpurcbDao;
import cn.gson.fengboot.model.mapper.QguigeMapper;
import cn.gson.fengboot.model.mapper.QhandledMapper;
import cn.gson.fengboot.model.pojos.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class QhandledService {
    @Autowired
    QhandledMapper qhandledMapper;
    @Autowired
    QpurDao qpurDao;
    @Autowired
    QpurcbDao qpurcbDao;

    public List<QhandledEntity> QhandledList(){
        return qhandledMapper.QhandledList();
    }

    public void  addcpcg(QpurchaseEntity qcaigouxz){
        Date date = new Date();
        Timestamp nousedate = new Timestamp(date.getTime());
        qcaigouxz.setPurchaseCgdate(nousedate);
        QpurchaseEntity save = qpurDao.save(qcaigouxz);
        save.getQpurchasecbEntities().forEach(a->{
            a.setPurchaseId(save);
        });

        System.out.println(qcaigouxz);
        qpurcbDao.saveAll(save.getQpurchasecbEntities());
    }

}
